<template>
	<view>
		<u-navbar back-icon-color="#ffffff" title=" " :border-bottom="false" :background="background">
			<view class="nav-title">
				<u-image :src="appletImgUrl+'rush-nav-title-image.png'" width="180" height="40"></u-image>
			</view>
		</u-navbar>
		<view class="main">
			<view class="bg-mask" :style="{
			top:uTabOffsetTop + 'px'
		}"></view>
			<view class="u-tab" :style="{
			top:uTabOffsetTop + 'px'
		}">
				<u-tabs :bar-style="{'background-color':'#00FFFF','border-radius':'3rpx'}" name="className" bg-color="rgba(0,0,0,0)" active-color="#ffffff" inactive-color="#ffffff" :list="navList"
				 :current="current" @change="change"></u-tabs>
			</view>

			<view class="list-status" v-if="loading || empty">
				<u-loading v-if="loading"></u-loading>
				<u-empty mode="list" v-if="empty"></u-empty>
			</view>
			<view class="list" v-if="list != ''">
				<view class="item" @click="$u.route('/pages/productDetail/productDetail',{id:item.id})" v-for="(item,index) in list"
				 :key="index">
				 <view style="width: 280rpx;">
				 	<u-lazy-load height="280" img-mode="aspectFill" border-radius="20"  :image="item.goodsMainPhoto"></u-lazy-load>
				 </view>
					<!-- <u-image :src="item.goodsMainPhoto" width="280" height="280" border-radius="20rpx"></u-image> -->
					<view class="info">
						<view class="title"><text v-if="item.groupBuyPersonCount">{{item.groupBuyPersonCount}}人团</text> {{item.goodsName}}</view>
						<view class="tag-box">
							<view class="tag">
								抢中赚红包：<text>￥{{item.goodsRedPacket}}</text>
							</view>
							<!-- <view class="tag">
								抢中赚红包：<text>￥{{item.goodsRedPacket}}</text>
							</view> -->
							<!-- <view class="tag" style="margin-left: 30rpx;" v-if="item.groupBuyPersonCount">
								{{item.groupBuyPersonCount}}人团
							</view> -->
						</view>
						<!-- <view class="status">正在抢购</view> -->

						<view class="order">
							<view class="money"><text>￥</text>{{item.groupBuyPrice}}</view>
							<view class="btn">立即购</view>
						</view>
					</view>
				</view>
				<u-gap></u-gap>
				<u-loadmore :status="status"></u-loadmore>
				<u-gap></u-gap>
			</view>
		</view>
	</view>
</template>

<script>
import {appletImgUrl} from "@/common/config.js"
	export default {
		data() {
			return {
				appletImgUrl:appletImgUrl,
				current: 0,
				uTabOffsetTop: 44 + uni.getSystemInfoSync().statusBarHeight,
				navList: [],
				loading: true,
				empty: false,
				status: 'loading',
				list: [],
				background: {
					backgroundImage: 'linear-gradient(90deg, #FF7200, #FFA200)'
				}
			};
		},
		onLoad() {
			this.pageNo = 1
			this.firstGoodsClassId = ''
			this.$u.get('goodsclass/getGoodsClassBylevel/1').then(res => {
				res.unshift({
					className: '精选',
					id: ''
				})
				this.navList = res
			})
			this.getList(res => {
				this.list = res.list
				this.loading = false
				if (this.list.length < 10) {
					this.status = 'nomore'
				} else {
					this.status = 'loadmore'
				}
				if (this.list == '') this.empty = true
			})
		},
		onReachBottom() {
			if (this.status == 'loading' || this.status == 'nomore') return
			this.pageNo++
			this.status = 'loading'
			this.getList(res => {
				if (res.list == '') {
					this.status = 'nomore'
					return
				}
				this.list = this.list.concat(res.list)
				this.status = 'loadmore'
			})
		},
		methods: {
			getList(callback) {
				this.$u.post('/goods/list', {
					pageNo: this.pageNo,
					pageSize: 10,
					isGroupingGoods: true,
					firstGoodsClassId: this.firstGoodsClassId
				}).then(res => {
					res.list.forEach(item => {
						let transformationArray = item.goodsMainPhoto.split(',')
						item.goodsMainPhoto = this.imageURL + transformationArray[0]
					})
					callback(res)
				})
			},
			change(index) {
				this.current = index;
				this.firstGoodsClassId = this.navList[index].id
				this.loading = true
				this.empty = false
				this.pageNo = 1
				this.list = []
				this.status = 'loading'
				this.getList(res => {
					this.list = res.list
					this.loading = false
					if (this.list.length < 10) {
						this.status = 'nomore'
					} else {
						this.status = 'loadmore'
					}
					if (this.list == '') this.empty = true
				})
			}
		}
	}
</script>

<style lang="scss">
	.list-status {
		display: flex;
		justify-content: center;
		align-items: center;
		height: 50vh;
	}

	.main {
		position: relative;
	}

	.list {
		padding: 0 30rpx;

		.item {
			margin-top: 30rpx;
			position: relative;
			z-index: 1;
			box-shadow: 0px 0 12px 1px rgba(203, 203, 202, 0.2);
			border-radius: 20rpx;
			background-color: #FFFFFF;
			display: flex;

			.info {
				padding: 20rpx 25rpx;
				position: relative;

				.order {
					position: absolute;
					padding-left: 25rpx;
					bottom: 20rpx;
					left: 0;
					width: 100%;
					display: flex;
					justify-content: space-between;
					align-items: center;

					.money {
						color: #FF4E47;
						font-size: 48rpx;
						font-weight: bold;

						text {
							font-size: 24rpx;
						}
					}

					.btn {
						color: #ffffff;
						text-align: center;
						line-height: 64rpx;
						width: 120rpx;
						background: linear-gradient(90deg, #FF3768, #FC6161);
						border-radius: 28px 0px 0px 28px;
					}
				}

				flex: 1;

				.status {
					color: #FF4E47;
					font-size: 22rpx;
				}

				.tag {
					// margin: 5rpx 0;
					color: #fff;
					display: flex;
					justify-content: space-between;
					width: 300rpx;
					padding: 3rpx 15rpx;
					font-size: 26rpx;
					background: url('~@/static/product-list-tag-bg.png')no-repeat center / 100% 100%;
					&:first-child{
						margin-bottom: 10rpx;
					}
					text{
						color: #FF4D46;
					}
				}

				.title {
					display: -webkit-box;
					font-weight: bold;
					font-size: 36rpx;
					-webkit-box-orient: vertical;
					-webkit-line-clamp: 2;
					margin-bottom: 10rpx;
					overflow: hidden;
					text{
						color: #fff;
						font-size: 26rpx;
						padding: 2rpx 10rpx;
						margin-right: 10rpx;
						background: linear-gradient(90deg, #FF3768, #FC6161);
						border-radius: 6rpx;
					}
				}
			}
		}
	}

	.bg-mask {
		background: linear-gradient(90deg, #FF7200, #FFA200);
		height: 300rpx;
		position: fixed;
		width: 100%;
		top: 0;
		left: 0;
	}

	.nav-title {
		width: 138px;
		position: absolute;
		left: 375rpx;
		transform: translateX(-50%);
		display: flex;
		align-items: center;
		justify-content: center;
		// background-color: red;
	}

	.u-tab {
		position: sticky;
		left: 0;
		z-index: 10;
		background: linear-gradient(90deg, #FF7200, #FFA200);
	}
</style>
